package com.hnevc.xiewenguang;

import java.util.Iterator;
import java.util.LinkedList;

/**
 *
 * 使用LinkedList集合
 * 增删操作
 * 使用迭代器iterator遍历集合
 *
 * foreach循环遍历
 */

public class Example02 {

    public static void main(String[] args) {
        LinkedList<String> linkedList = new LinkedList();
        linkedList.add("demo01");
        linkedList.add("demo02");
        linkedList.add("demo03");
        System.out.println(linkedList.toString());
        linkedList.add(2,"demo04");
        linkedList.addFirst("demo05");
        linkedList.addLast("demo06");
        System.out.println(linkedList);
        linkedList.remove(4);
        linkedList.removeFirst();
        System.out.println(linkedList);
        //遍历集合
        Iterator it = linkedList.iterator();
        while (it.hasNext()){
            Object o = it.next();
            System.out.println(o);
        }

        for (String str : linkedList){
            System.out.println(str);
        }
    }

}
